Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: dev-env scripts #1045

Closed
wants to merge 11 commits into from

Conversation

ochicf
Copy link

@ochicf ochicf commented May 20, 2024

Context

Related to #720, attempts to solve the issue with NextAuth's AUTH_URL and Expo.

See relevant comments:


Highlights

  • general:
    • add a system to generate/infer certain env vars for running the apps in development mode
    • the generation/inference is tied in turbo, so it will run before any of the projects (so they are visible to any app)
  • nextjs
    • launches the app with a custom hostname, so it's available though LAN
    • has a script that writes the env vars (infered from api and auth packages)
  • expo
    • reads the API URL from an env var (which in development is infered from hostname and port of the nextjs app)

Benefits

  • should need 0 initial config related to AUTH_URL (which was the initial objective)
  • expo's API URL is better constructed (for example, will respect the port)
  • nextjs app is accessible through LAN (useful to access from mobile phone?)
  • everything is still configurable from .env in workspace root
  • expo API URL on production will be read from env var
  • minimal runtime code has been modified

Drawbacks

  • nextjs app must be accessed from the network IP instead of localhost (it's shown when the app has started)
  • any change in network devices will affect in the nextjs accessible address. The worst part of this is that oauth redirects need to be whitelisted in certain providers (ex: Discord), so this is a bit annoying as new ones need to be added
  • inference logic may fail depending on the device/system (though note that .env has full control if env vars are specified there)
  • the approach may be incorrect/too complex - I'm biased on this so I'll let others judge!

Screen-capture

Screen.Recording.2024-05-28.at.16.47.51.mov
Screen.Recording.2024-05-28.at.16.29.45.mov

Screenshots

Run project from workspace root

Screenshot 2024-05-28 at 16 27 22

Resulting `.env` files

Screenshot 2024-05-28 at 16 25 42
Screenshot 2024-05-28 at 16 25 57

Running apps

Screenshot 2024-05-28 at 16 30 12

TODO

  • Document how to manage env vars when doing a production build of the Expo app

@ochicf ochicf mentioned this pull request May 20, 2024
…nv files for itself

This is needed to know which env variables will be actually read afterwards, and avoid unnecessary logic/logging
@ochicf
Copy link
Author

ochicf commented May 29, 2024

Closed in favor of #1054.

@ochicf ochicf closed this May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant